﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Photon.SocketServer;
using ExitGames.Logging;
using ExitGames.Logging.Log4Net;
using System.IO;
using log4net.Config;

namespace GameServer
{
    public class ServerMain : ApplicationBase
    {
        private static readonly ILogger logger = LogManager.GetCurrentClassLogger();

        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            return new MyClientPeer(initRequest);
        }

        protected override void Setup()
        {
            // 设置生成的日志文件的目录
            log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = 
                Path.Combine(
                Path.Combine(this.ApplicationRootPath, "bin_Win64"),
                "log");

            // 用Path.Combine可以屏蔽平台的差异性，this.Binary是游戏的bin目录
            FileInfo configFile = new FileInfo(Path.Combine(this.BinaryPath, "log4net.config"));
            if (configFile.Exists) {
                // using ExitGames.Logging.Log4Net;
                LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
                // using log4net.Config;  让photon知道我们用的是log4net插件
                XmlConfigurator.ConfigureAndWatch(configFile);
                logger.Info("log config completed !!!!");
            }
            
        }

        protected override void TearDown()
        {
        }
    }
}
